import Vue from 'vue'
import axios from 'axios';
import {
    BASE_URL
} from '@/config'
import ViewUI from 'view-design';
Vue.use(ViewUI);
// console.log(BASE_URL)
const instance = axios.create({
    baseURL: BASE_URL,
    timeout: 3000,
    // headers: {'X-Custom-Header': 'foobar'}
});

// 添加请求拦截器
instance.interceptors.request.use(function (config) {
    ViewUI.LoadingBar.start()
    return config;
  }, function (error) {
    ViewUI.LoadingBar.error()
    return Promise.reject(error);
  });

// 添加响应拦截器
instance.interceptors.response.use(function (response) {
    ViewUI.LoadingBar.finish()
    return response;
  }, function (error) {
    ViewUI.LoadingBar.error()
    return Promise.reject(error);
  });

  export default instance